package org.jeecgframework.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.jeecgframework.core.common.controller.BaseController;
import org.jeecgframework.core.common.model.json.AjaxJson;
import org.jeecgframework.web.service.UploadInstallRecordService;
import org.jeecgframework.web.service.ZyCommonService;
import org.jeecgframework.web.system.pojo.base.ZyFileLogEntity;
import org.jeecgframework.web.system.service.SystemService;
import org.jeecgframework.web.util.FileBean;
import org.jeecgframework.web.util.UploadFileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * @Title: Controller
 * @Description: 上传安装记录
 * @author ZhangYunlong
 * @date 2016-04-11 11:35:24
 * @version V1.0
 * 
 */
@Scope("prototype")
@Controller
@RequestMapping("/uploadInstallRecordController")
public class UploadInstallRecordController extends BaseController {
	/**
	 * Logger for this class
	 */
	@SuppressWarnings("unused")
	private static final Logger logger = Logger.getLogger(UploadInstallRecordController.class);

	@Autowired
	private UploadInstallRecordService uploadInstallRecordService;

	@Autowired
	private SystemService systemService;

	@Autowired
	private ZyCommonService zyCommonService;

	private String message;

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	/**
	 * 文件管理列表 页面跳转
	 * 
	 * @return
	 */
	@RequestMapping(params = "uploadFile")
	public ModelAndView fileLog(HttpServletRequest request) {
		return new ModelAndView("com/zybk/zy_upload_install_record/uploadInstallRecord");
	}

	/**
	 * @Title：importExcel
	 * @Description：导入上传安装记录Excel
	 * @author：LeiYoung
	 * @Date：2016年9月29日 下午4:00:56
	 * @param request
	 * @param response
	 * @return AjaxJson
	 */
	@ResponseBody
	@RequestMapping(params = "importExcel")
	public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {

		AjaxJson j = new AjaxJson();

		ZyFileLogEntity fileLog = null;

		try {

			FileBean fileBean = UploadFileUtil.UploadFile(request);

			fileLog = uploadInstallRecordService.doSaveZyFileLogEntity(fileBean);

			j.setObj(fileLog);

			j.setSuccess(true);

		} catch (Exception e) {

			j.setObj(e.getMessage());

			j.setSuccess(false);

			e.printStackTrace();

		}

		return j;
	}

	/**
	 * @Title：checkExcelSn
	 * @Description：解析Excel中SN是否不为空
	 * @author：LeiYoung
	 * @Date：2016年9月29日 下午5:20:08
	 * @param request
	 * @param response
	 * @return AjaxJson
	 */
	@ResponseBody
	@RequestMapping(params = "checkExcelSn", method = RequestMethod.POST)
	public AjaxJson checkExcelSn(HttpServletRequest request, HttpServletResponse response) {

		AjaxJson j = null;
		
		try {

			j = uploadInstallRecordService.checkExcelSn(request);

		} catch (Exception e) {

			e.printStackTrace();

		}

		return j;
	}
}
